// createRouter:创建router实例
// createWebHistory : 创建history模式路由

import { createRouter, createWebHistory } from 'vue-router'
import Login from '@/views/Login/index.vue'
import Layout from '@/views/Layout/index.vue'
import Home from '@/views/Home/index.vue'
import Categroy from '@/views/Categroy/index.vue'
import SubCategroy from '@/views/SubCategroy/index.vue'
import Detail from '@/views/Detail/index.vue'
import CartList from '@/views/CartList/index.vue'
import CheckOut from '@/views/CheckOut/index.vue'
import Pay from '@/views/Pay/index.vue'
import PayBack from '@/views/Pay/PayBack.vue'
import Member from '@/views/Member/index.vue'
import UserInfo from '@/views/Member/components/UserInfo.vue'
import UserOrder from '@/views/Member/components/UserOrder.vue'
import Ceshi from '@/views/CeShi/index.vue'
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      component: Layout,
      children: [
        {
          path: '',
          component: Home
        },
        {
          path: 'categroy/:id',
          component: Categroy
        },
        {
          path: 'categroy/sub/:id',
          component: SubCategroy
        },
        {
          path: 'detail/:id',
          component: Detail
        },
        {
          path: 'CartList',
          component: CartList
        },
        {
          path: 'checkout',
          component: CheckOut
        },
        {
          path: 'pay',
          component: Pay
        },
        {
          path: 'payback',
          component: PayBack
        },
        {
          path: 'member',
          component: Member,
          children: [
            {
              // 当出现路由嵌套的时候 希望在二级路由member显示的时候把user组件作为默认选项显示出来 可以把user滞空
              path: '',
              component: UserInfo
            },
            {
              path: 'order',
              component: UserOrder
            }
          ]
        },
        {
          path: 'ceshi',
          component: Ceshi
        }
      ]
    },
    {
      path: '/login',
      component: Login
    }
  ],
  // 路由行为的配置项 路由切换的时候自动滚到顶部
  scrollBehavior() {
    return {
      top: 0
    }
  }
})

export default router
